<template>
  <div>
    <el-dialog
      v-model="manufacturing"
      v-if="manufacturing"
      top="15%"
      width="53%"
      title="生产线楼层"
      @close="handleClose"
      :close-on-click-modal="false"
      ><el-table :data="tableData" border class="table" ref="multipleTable">
        <el-table-column prop="id" label="序列号" width="65" align="center">
          <template #default="scope">
            {{ Number(scope.$index + 1) }}
          </template>
        </el-table-column>
        <el-table-column prop="buildName" label="楼层名称">
          <template #default="scope">
            <el-button type="text" @click="handleBuild(scope.row)">{{
              scope.row.buildName
            }}</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="electricQuantity" label="月消耗电量（kwh）">
        </el-table-column>
        <el-table-column prop="totalPower" label="总耗电量（kwh）">
        </el-table-column>
        <el-table-column label="操作" width="180" align="center">
          <template #default="scope">
            <el-button type="text" @click="handleExport(scope.row)"
              >导出</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>
<script>
import axios from "axios";
import { ref, reactive, onMounted } from "vue";
import api from "../../api/api";
export default {
  components: {},
  setup(props, conts) {
    const manufacturing = conts.attrs.manufacturing;
    const tableData = ref([
      {
        buildName: "厂房二楼",
        electricQuantity: "1212",
        totalPower: "4242",
      },
      {
        buildName: "厂房二楼",
        electricQuantity: "1131",
        totalPower: "1313",
      },
    ]);
    const handleExport = () => {
      // api
      //   .postFormAPI("backup/alarmInfo/exportExcel", {})
      //   .then((res) => {
      //     if (res.data.code == 1) {
      //       getdownload(res.data.data);
      //     } else {
      //       ElMessage.error(res.data.message);
      //     }
      //     //数据处理
      //   })
      //   .catch((err) => {});
    };
    const getdownload = (code) => {
      proxy
        .$axios({
          method: "GET",
          url: api.getUrl() + "backup/excel/download?code=" + code,
          responseType: "blob",
        })
        .then((resdata) => {
          download(resdata.data, "历史报警.xlsx");
        })
        .catch((err) => {
          ElMessage.error(err.response);
        });
    };
    const handleClose = () => {
      conts.emit("handleClose", false);
    };
    const handleBuild = (row) => {
      conts.emit("handleBuild", row);
    };
    return { manufacturing, tableData, handleExport, handleClose, handleBuild };
  },
};
</script>